﻿using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Text;
using QzEbook.AccessObject;
using QzEbook.Common;
using System.Collections.Generic;
using QzEbook.Common.Emum;
using QzEbook.Admin;
using System.IO;

public partial class module_detailItem : System.Web.UI.UserControl
{
    private StringBuilder sb;
    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    private void BindData()
    {

        int Bid = int.Parse(Request["Bid"]);

        string sessionName = String.Format("{0}HitDetailFinished", Bid);
        if (Session[sessionName]==null||!(bool)Session[sessionName])
        {
            Hit hit = new Hit();
            hit.BId = Bid;
            hit.Type = HitAction.HitDetail;
            hit.update();
            Session[sessionName] = true;
        }
        
        sb = new StringBuilder();

        Book book = new Book();
        book.BookId = Bid;
        book=book.select();
        this.Page.Title = book.Title;

        if (!book.IsVisible)
        {
            SessionUser userSession=Session[SessionManager.LOGINUSER] as SessionUser;
            if (userSession == null || userSession.Uid != book.EditorId)
            {
                sb.Append("<div id=\"bookItem\"><div class=\"viewItem\"><strong><img src='images/siteIcon/alert.gif' alt='有问题' />此书为私有书,你无权查看</strong></div></div>");
                return;
            }
        }


        

        sb.AppendLine("<div id=\"bookItem\">");

        sb.AppendLine("<div class=\"viewItem\">");
        sb.AppendFormat("<a href=\"Viewer.xhtml?Bid={0}\" title=\"{1}\" class=\"viewThumb\" >", book.BookId, book.Title);
        
        string path=string.Format("{0}{1}",Config.UserBookSavePath,book.Thumb);
        if(!File.Exists(Server.MapPath(path))){
            path="images/siteIcon/error.gif";
        }

        sb.AppendFormat("<img src=\"{0}\" alt=\"点击查看\"/>", path);
        sb.Append("<br /><img src=\"images/siteIcon/viewerBtn.gif\" alt=\"点击查看\" class=\"viewerBtn\" />");
        sb.AppendLine("</a>");

        sb.AppendLine(" <ins>");

        if (book.isSale)
        {
            sb.AppendLine("<dfn class='auditing'><img src=\"images/siteIcon/auditing.gif\" alt='收费' /></dfn>");
        }
        sb.AppendFormat("<acronym><strong>标题:</strong>{0}</acronym>", book.Title);
        sb.AppendFormat("<a href=\"Feed.xhtml?Bid={0}\" title=\"查看rss\"><img src=\"images/rss.gif\" alt=\"此书RSS\" /></a>", book.BookId);
        sb.AppendFormat("<a href=\"user.xhtml?Uid={0}\" title='作者'><img src='images/icon_user.gif' alt='作者' /></a>", book.EditorId);

        if (book.isSale)
        {
            sb.AppendFormat("<acronym id=\"buyAction\"><strong>价格:</strong>{0}元", book.Price);
            sb.AppendFormat("<a href=\"buy.xhtml?Bid={0}\" title='购买'><img src='images/siteIcon/buy.gif' alt='购买' /></a></acronym>", book.BookId);
            
        }
        sb.AppendFormat("<acronym><strong>分类:</strong><a href=\"list.xhtml?Cid={0}\" title={1}>{1}</a></acronym>", book.CategoryId, Category.getName(book.CategoryId));
        sb.AppendFormat("<acronym><strong>标签:</strong>{0}</acronym>", book.getTagListHTML());
        sb.AppendFormat("<kbd><strong>日期:</strong>{0}</kbd>", book.PostDate.ToString("f"));
        sb.AppendFormat("<address><strong>浏览地址:</strong><input type=\"text\" id=\"viewAddress\" value=\"http://www.newpub.cn/Viewer.xhtml?Bid={0}\" /></address>", book.BookId);

        StringBuilder blogCode = new StringBuilder();
        blogCode.Append("<object width=\'550\' height=\'400\'>");
        blogCode.Append("<param name=\'movie\' value=\'http://www.newpub.cn/QzReader/singlepage.swf\'></param>");
        blogCode.Append("<param name=\'allowScriptAccess\' value=\'always\'></param>");
        blogCode.AppendFormat("<param name=\'flashvars\' value=\'configxml=http://www.newpub.cn/getconfig.aspx?Bid={0}\' />", book.BookId);
        blogCode.Append("<param name=\'allowFullScreen\' value=\'true\'></param>");
        blogCode.AppendFormat("<embed src=\'http://www.newpub.cn/QzReader/singlepage.swf\' type=\'application/x-shockwave-flash\' flashvars=\'configxml=http://www.newpub.cn/getconfig.aspx?Bid={0}\' width=\'550\' height=\'400\' allowFullScreen=\'true\' allowScriptAccess=\'always\'></embed>", book.BookId);
        blogCode.Append("</object>");
        
        sb.AppendFormat("<address><strong>blog代码:</strong><input type=\"text\" id=\"blogCode\" value=\"{0}\" /></address>",blogCode.ToString());
        sb.AppendLine(" </ins>");
        sb.AppendFormat("<cite><strong>点击数:{0} </strong><strong>阅读数:</strong>{1} <strong>收藏人数:</strong>{2} <strong>评论数:</strong>{3}</cite> ", book.Hit,book.Readers,book.Favorites, book.Comments);
        sb.AppendLine("</div>");

        sb.AppendLine("<div id=\"viewContent\" class=\"HTMLContent \">");
        sb.AppendLine("<h1>");
        sb.AppendFormat("{0}相关介绍", book.Title);
        sb.AppendLine("</h1>");
        sb.AppendLine(book.Content.ToString());
        sb.AppendLine("</div>");

        sb.AppendLine("</div>");

    }
    protected override void Render(HtmlTextWriter writer)
    {
        if (sb != null)
        {
            writer.Write(sb.ToString());
        }
        base.Render(writer);
    }
}
